package com.face.console.controller;

import com.face.console.pojo.dto.RoleDto;
import com.face.console.pojo.request.RoleIdAndMenuIdsRequest;
import com.face.console.service.RoleService;
import com.face.console.tools.BaseControoler;
import com.face.console.tools.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 角色管理
 */
@RestController
@RequestMapping(value = "/api/role")
public class RoleController extends BaseControoler {

    @Autowired
    private RoleService roleService;

    @PostMapping(value = "/manger-menu")
    public R mangerMenu(@RequestBody RoleIdAndMenuIdsRequest request) {
        return roleService.mangerMenu(request);
    }

    @PostMapping(value = "/{roleId}/menu-list")
    public R selectAllMenuByRoleId(@RequestParam("roleId") long roleId) {
        return roleService.selectAllMenuByRoleId(roleId);
    }

    @PostMapping(value = "/save")
    public R saveRole(@RequestBody RoleDto role) {
        return roleService.saveRole(role);
    }

    @PostMapping(value = "/{id}/del")
    public R delRole(@RequestParam("id") Long id ) {
        return roleService.delRoleById(id);
    }

    ;
}
